<template>
	<view class="person-info-page relative">
		<image v-if="commonConfigs && commonConfigs.domainFrontFileLink" :src="`${commonConfigs.domainFrontFileLink}/files/images/page-bg.png`" class="bg" />
		<comDetailNavigateBack title="个人资料" />

		<comScrollTab v-model="tabIndex" :list="tabAreaList">
			<scroll-view scroll-y class="personInfo-box relative" :style="{ height: 'calc(100vh - ' + commonNavHeight + ' - 90rpx)' }">
				<!-- 昵称头像 -->
				<view v-if="tabIndex === 0">
					<comBasicInfo />
				</view>
				<!-- 我的地址 -->
				<view v-if="tabIndex === 1">
					<comAddressInfo :list="list" @clickDelete="clickDelete" :fromType="fromType" @clickRadio="clickRadio" />
				</view>
			</scroll-view>
		</comScrollTab>
		
		<!-- 小程序隐私保护指引设置 -->
		<!-- #ifdef MP-WEIXIN -->
		<comPrivacyPopup senceOrign="sceneNull" style="z-index: 100000;" title="用户隐私保护提示" popupOfHeight="482rpx"></comPrivacyPopup>
		<!-- #endif -->
	</view>
</template>

<script>
	import store from '@/store';
	import { getUserAddressListApi, getUserAddressEditApi, getUserAddressDeleteApi } from '@/setupproject/INTERFACE';
	export default {
		name: 'personInfoPage',
		data() {
			return {
				fromType: '',
				list: [],
				tabIndex: 0,
				tabAreaList: [{ text: '昵称头像' }, { text: '我的地址' }],
				// tabAreaList: [{ text: '昵称头像' }, { text: '我的信息' }, { text: '我的地址' }],
			};
		},
		onShow: function () { 
			this.resListsGetFun();
		},
		computed: {
			commonConfigs() {
				return store.getters.commonConfigs || {};
			},
			commonNavHeight() { 
				return store.getters.commonNavHeight + 'px';
			},
			
		},
		onLoad({ type, fromType }) {
			this.tabIndex = Number(type) || 0;
			this.fromType = fromType || '';
		},
		methods: {
			// 删除
			async clickDelete(item) {
				const [em, modal] = await uni.showModal({
					content: '确认删除吗'
				});
			
				if (!modal.confirm) return;
				const { data, code } = await getUserAddressDeleteApi(item);
			
				if (code === 200) {
					this.resListsGetFun();
				}
			},
			
			async clickRadio(item) {
				item.is_default = 1;
				const resp = await getUserAddressEditApi(item)
			
				this.resListsGetFun();
			},
			// 获取已有地址
			async resListsGetFun() {
				const resp = await getUserAddressListApi();
				this.list = resp.data.address_list;
			},
			
		}
	};
</script>

<style scoped lang="scss">
	.person-info-page {
		width: 100%;
		height: 100%;
		.personInfo-box {
			padding-bottom: 20rpx;
		}
	}
</style>
